package com.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cs.domain.Prod;
import com.cs.es.ProdEs;
import com.cs.service.ProdCommService;
import com.cs.service.ProdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prod/prod")
@Api(tags = "商品管理的接口")
public class ProdController {

    @Autowired
    private ProdService prodService;

    /**
     * 分页查询商品的接口
     * @param page
     * @param prod
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询商品的接口")
    @PreAuthorize("hasAuthority('prod:prod:page')")
    public ResponseEntity<Page<Prod>> findProdPage(Page<Prod> page,Prod prod){
        Page<Prod> prodPage=prodService.findProdPage(page,prod);
        return ResponseEntity.ok(prodPage);
    }

    /**
     * 上架商品
     *
     * @param prod
     * @return
     */
    @PostMapping
    @ApiOperation("上架商品")
    @PreAuthorize("hasAuthority('prod:prod:save')")
    public ResponseEntity<Void> saveProd(@RequestBody Prod prod) {
        prodService.save(prod);
        return ResponseEntity.ok().build();
    }




}
